package com.itheima.tlias.exception;


import com.itheima.tlias.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自定义全局异常处理器，处理项目中抛出的业务异常
 */
@RestControllerAdvice //表示当前类是SpringMVC中的异常处理器
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 捕获业务异常
     *
     * @param
     * @return
     */
    @ExceptionHandler(value = BusinessException.class)
    public Result exceptionHandler(BusinessException e) {
        log.error("异常信息：", e);
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public Result exceptionHandler(Exception ex) {
        log.error("异常信息：{}", ex.getMessage());
        return Result.error("服务器异常，请稍后再试");
    }

}
